/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"E1F1D201-AB48-4D0D-88E5-B958A707D08A"}
 */
function onDataChange_codigo(oldValue, newValue, event) {
	if (controller.getSelectedIndex() == 1 && globals.gEstadoAbm == 1)
	{
		elements.nombre.requestFocus()
		return true
	}
	else
	{
		elements.nombre.requestFocus()
		codigo = oldValue
		return true
	}
}

/**
 * @properties={typeid:24,uuid:"D526A954-9E8A-414D-9F59-B1DB10409672"}
 * @AllowToRunInFind
 */
function validar() {
	controller.setSelectedIndex(1)
	if (globals.gEstadoAbm == 1)
	{
		var $sql = 'SELECT capitulo_id FROM capitulo WHERE codigo = ? AND empresa = ?'
		var $args = [codigo, globals.gUservID]
		var $ds = databaseManager.getDataSetByQuery('contable',$sql,$args,-1)
		
		if ($ds.getMaxRowIndex() != 0) 
		{		
			return [false,false,"El código ingresado ya existe"]
		}
	}
	return [true]
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"A67519BE-01DD-4B43-BA7B-76806E4BD21B"}
 */
function onShow(firstShow, event) {
	controller.sort("codigo asc")
}

/**
 * @properties={typeid:24,uuid:"14CE1CDE-56A2-4610-B834-700A44638A6B"}
 */
function imprimir() {
	//forms.capitulo_impresion.controller.showPrintPreview()
	jasper('impresion')
}

/**
 * @properties={typeid:24,uuid:"F4BBD13F-B9E0-4048-A6D5-B1718428B89C"}
 */
function pdf() {
	//globals.metodoPdf('capitulo_impresion','capitulos - '+globals.glegajo,true)
	jasper('pdf')
}

/**
 * @properties={typeid:24,uuid:"0FDBE008-348F-4623-9417-EA0576072E39"}
 */
function xls()
{
	jasper('xls')
}

/**
 * @properties={typeid:24,uuid:"E6114A00-77A0-49E9-B97B-9D1846B3C21E"}
 */
function csv()
{
	jasper('csv')
}

/**
 * @param {String} tipo
 * @properties={typeid:24,uuid:"D90B952B-DDE0-449F-A34B-D7D84FB56461"}
 */
function jasper(tipo)
{
	var $params = {
		userv: usuarios_to_uservs.razon_social
	}
	
	globals.metodoJasper(tipo,'contable/capitulos.jasper','Capitulos',foundset,$params)
}